clear 

use "$P_Data_Processed/monthly_station_data_e5_merged.dta", clear
 
capture drop other_brand_share
sort mktid year_month StID

by mktid year_month: gener other_brand_share = share_others_treated[_n+1] if _n<_N & Brand!=Brand[_n+1]
by mktid year_month: replace other_brand_share = share_others_treated[1] if _n==_N  

reghdfe treat other_brand_share n_act_stations n_mkt_compet_adopt l_gdp pop_density med_age employed_share l_pop n_brand mean_temp sd_temp mean_precip sd_precip , absorb(year_month StID) cluster(mktid)
	outreg2 using "$P_Tables/Table_G7", replace tex(frag) label dec(3) keep(other_brand_share)
	
	ivreghdfe mean_wh_margin  n_act_stations n_mkt_compet_adopt l_gdp pop_density med_age employed_share l_pop n_brand mean_temp sd_temp mean_precip sd_precip  (treat = other_brand_share) if year<2019, absorb(year_month StID) cluster(mktid) 
	outreg2 using "$P_Tables/Table_G7", append tex(frag) label dec(3) keep(treat)

	ivreghdfe mean_price   n_act_stations n_mkt_compet_adopt l_gdp pop_density med_age employed_share l_pop n_brand mean_temp sd_temp mean_precip sd_precip  (treat = other_brand_share) if year<2019, absorb(year_month StID) cluster(mktid) 
	outreg2 using "$P_Tables/Table_G7", append tex(frag) label dec(3) keep(treat)

